package ceshi;

import java.io.File;
import java.io.FileInputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.PipedInputStream;
import java.io.PipedOutputStream;

public class Test {

	public static String objectToString(File o) throws Exception {

		PipedInputStream pis = new PipedInputStream();
		PipedOutputStream pos = new PipedOutputStream(pis);

		ObjectOutputStream oos = new ObjectOutputStream(pos);
		oos.writeObject(o);
		oos.close();

		int count = pis.available();
		byte[] buf = new byte[count];
		pis.read(buf);
		pis.close();
		pos.close();

		return Base64.getBase64(buf);
	}

	public static Object stringToObject(String s) throws Exception {
		byte[] buf = Base64.base64ToByte(s);

		PipedInputStream pis = new PipedInputStream();
		PipedOutputStream pos = new PipedOutputStream(pis);
		pos.write(buf);
		ObjectInputStream ois = new ObjectInputStream(pis);
		Object o = ois.readObject();
		ois.close();
		pis.close();
		pos.close();
		// new file
		return o;
	}

	public static void main(String[] args) throws Exception {
		// Stream s =
		// Files.lines(Paths.get("C:\\Users\\Ems\\Documents\\莲师消除障道祈请颂.txt"));
		// s.filter(line -> !line.trim().equals(""))
		// .forEach(line -> System.out.println(line));
		// s.close();
		// PipedInputStream pis = new PipedInputStream();
		// PipedOutputStream pos = new PipedOutputStream(pis);
		//
		// ObjectOutputStream oos = new ObjectOutputStream(pos);
		// oos.writeObject(new myObj("Emerson", 1000000));
		//
		// ObjectInputStream ois = new ObjectInputStream(pis);
		// myObj mo = (myObj) ois.readObject();

		
		String s = "123456";
//		s.l
		char[] a=s.toCharArray();
		String x=s.substring(0, 3);
		System.out.println(x);
	}

}
